﻿var Extend_CollectSetInfoList;
var Extend_CollectSetInfoStore;

// 功能模块grid展示
Extend_CollectSetInfoList = function () {
    Ext.Loader.setConfig({ enabled: true });
    Ext.Loader.setPath('Ext.ux', '../../js/ext/ux');
    Ext.require([
    'Ext.ux.comboboxtree'
]);
    Ext.Ajax.timeout = 240000;
    var url = "/manager/Extend_CollectSetInfo/List";
    var sm = Ext.create('Ext.selection.CheckboxModel');

    //grid 填充
    Ext.define('Extend_CollectSetInfoGridModel', {
        extend: 'Ext.data.Model',
        fields: [
            { name: "Id", type: "string" },
            { name: "Name", type: "string" },
            { name: "Url", type: "string" },
            { name: "Encoding", type: "string" },
            { name: "IncludeStr", type: "string" },
            { name: "StartNum", type: "string" },
            { name: "EndNum", type: "string" },
            { name: "AddNum", type: "string" },
            { name: "WithoutStr", type: "string" },
            { name: "Enabled", type: "string" },
            { name: "ChannelId", type: "string" },
            { name: "TitleReplaceStr", type: "string" },
            { name: "IsAutoKeyWord", type: "string" },
            { name: "IsAutoDescription", type: "string" },
            { name: "IsIncludeHtml", type: "string" },
            { name: "ContentMatchLeft", type: "string" },
            { name: "ContentMatchRight", type: "string" },
            { name: "ContentRemoveLeftLength", type: "string" },
            { name: "ContentRemoveRightLength", type: "string" },
            { name: "ContentReplaseStr", type: "string" },
            { name: "IsIncludeScript", type: "string" },
            { name: "IsIncludeClass", type: "string" },
            { name: "IsIncludeStyle", type: "string" },
            { name: "IsIncludeColor", type: "string" },
            { name: "IsIncludeLink", type: "string" },
            { name: "IsIncludeImg", type: "string" },
            { name: "IsIncludeFile", type: "string" },
            { name: "IsIncludeFrame", type: "string" },
            { name: "IsPaging", type: "string" },
            { name: "PagingReg", type: "string" },
            { name: "CollectTime", type: "datetime" },
            { name: "Cookie", type: "string" },
            { name: "ThreadInterval", type: "string" },
            { name: "OrderNum", type: "string" },
            { name: "IsAutoUpdate", type: "string" },
            { name: "DoTime", type: "string" }
            ]
    });

    //grid获取 json数组
    Extend_CollectSetInfoStore = Ext.create('Ext.data.Store', {
        pageSize: CMN.pageSize,
        model: 'Extend_CollectSetInfoGridModel',
        remoteSort: true, //加这个排序成功
        //buffered: false,  //是否动态加载
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: url,
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        },
        sorters: [{
            property: 'Id',
            direction: 'DESC'
        }]
    });

    //分页设置
    var pagingBar = Ext.create('Ext.PagingToolbar', {
        displayInfo: true, emptyMsg: "没有数据显示", displayMsg: "显示从{0}条数据到{1}条数据，共{2}条数据",
        store: Extend_CollectSetInfoStore,
        pageSize: CMN.pageSize,
        //显示右下角信息
        prevText: "上一页",
        nextText: "下一页",
        refreshText: "刷新",
        lastText: "最后页",
        firstText: "第一页",
        beforePageText: "当前页",
        afterPageText: "共{0}页"
    });

    //删除选中行信息
    DeleteExtend_CollectSetInfoFn = function () {
        var row = Ext.getCmp("Extend_CollectSetInfoPanel").getSelectionModel().getSelection();
        if (row.length == 0) {
            Ext.helper.msg("提示信息", "请您至少选择一个!");
        }
        else if (row.length > 1) {
            var idList = "";
            for (var i = 0; i < row.length; i++) {
                if (i == 0) {
                    idList = row[0].data.Id;
                }
                else {
                    idList = idList + "_" + row[i].data.Id;
                }
            }
            //Ext.helper.msg("提示信息", "对不起只能选择一个!");
            Ext.Msg.confirm("提 示!", "您确定要删除" + idList + "吗?", function (btn) {
                if (btn == "yes") {
                    Ext.Ajax.request({
                        url: "/manager/Extend_CollectSetInfo/DeleteList/" + idList,
                        method: "get",
                        success: function (d) {
                            //成功后
                            var action = Ext.JSON.decode(d.responseText);
                            //alert(action.success);
                            var flag = action.success;
                            if (flag == "true") {
                                Extend_CollectSetInfoStore.loadPage(pagingBar.getPageData().currentPage);
                                Ext.helper.msg("恭喜", "删除成功!");
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.helper.msg("删除失败!", message);
                                }
                                else {
                                    Ext.helper.msg("提示!", "删除失败!");
                                }
                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", "修改失败!");
                        }
                    })
                }
                else {

                }
            })
        }
        else if (row.length == 1) {
            Ext.Msg.confirm("提 示!", "您确定要删除" + row[0].data.Id + "吗?", function (btn) {
                if (btn == "yes") {
                    Ext.Ajax.request({
                        url: "/manager/Extend_CollectSetInfo/Delete/" + row[0].data.Id,
                        method: "POST",
                        success: function (d) {
                            //成功后
                            var action = Ext.JSON.decode(d.responseText);
                            //alert(action.success);
                            var flag = action.success;
                            Ext.MessageBox.hide();
                            if (flag == "true") {
                                Extend_CollectSetInfoStore.loadPage(pagingBar.getPageData().currentPage);

                                Ext.helper.msg("恭喜", "删除成功!");
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.helper.msg("删除失败!", message);
                                }
                                else {
                                    Ext.helper.msg("提示!", "删除失败!");
                                }
                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", "修改失败!");
                        }
                    })
                }
                else {

                }
            })
        }
    }


     //启用选中行信息
    UpdateEnabledFn = function () {
        var row = Ext.getCmp("Extend_CollectSetInfoPanel").getSelectionModel().getSelection();
        if (row.length == 0) {
            Ext.helper.msg("提示信息", "请您至少选择一个!");
        }
        
            var idList = "";
            for (var i = 0; i < row.length; i++) {
                if (i == 0) {
                    idList = row[0].data.Id;
                }
                else {
                    idList = idList + "_" + row[i].data.Id;
                }
            }
            //Ext.helper.msg("提示信息", "对不起只能选择一个!");
            Ext.Msg.confirm("提 示!", "您确定要启用" + idList + "吗?", function (btn) {
                if (btn == "yes") {
                    Ext.Ajax.request({
                        url: "/manager/Extend_CollectSetInfo/UpdateEnabled/" + idList,
                        method: "get",
                        success: function (d) {
                            //成功后
                            var action = Ext.JSON.decode(d.responseText);
                            //alert(action.success);
                            var flag = action.success;
                            if (flag == "true") {
                                Extend_CollectSetInfoStore.loadPage(pagingBar.getPageData().currentPage);
                                Ext.helper.msg("恭喜", "启用成功!");
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.helper.msg("启用失败!", message);
                                }
                                else {
                                    Ext.helper.msg("提示!", "启用失败!");
                                }
                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", "启用失败!");
                        }
                    })
                }
                else {

                }
            })
      
    }

      //启用自动更新行信息
    UpdateIsAutoUpdateFn = function () {
        var row = Ext.getCmp("Extend_CollectSetInfoPanel").getSelectionModel().getSelection();
        if (row.length == 0) {
            Ext.helper.msg("提示信息", "请您至少选择一个!");
        }
        
            var idList = "";
            for (var i = 0; i < row.length; i++) {
                if (i == 0) {
                    idList = row[0].data.Id;
                }
                else {
                    idList = idList + "_" + row[i].data.Id;
                }
            }
            //Ext.helper.msg("提示信息", "对不起只能选择一个!");
            Ext.Msg.confirm("提 示!", "您确定要启用自动更新" + idList + "吗?", function (btn) {
                if (btn == "yes") {
                    Ext.Ajax.request({
                        url: "/manager/Extend_CollectSetInfo/UpdateIsAutoUpdate/" + idList,
                        method: "get",
                        success: function (d) {
                            //成功后
                            var action = Ext.JSON.decode(d.responseText);
                            //alert(action.success);
                            var flag = action.success;
                            if (flag == "true") {
                                Extend_CollectSetInfoStore.loadPage(pagingBar.getPageData().currentPage);
                                Ext.helper.msg("恭喜", "启用自动更新成功!");
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.helper.msg("启用自动更新失败!", message);
                                }
                                else {
                                    Ext.helper.msg("提示!", "启用自动更新失败!");
                                }
                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", "启用自动更新失败!");
                        }
                    })
                }
                else {

                }
            })
      
    }

     UpdateIsPass = function (setId) {
    Ext.Msg.confirm("提 示!", "您确定要全部更新" + setId + "吗?", function (btn) {
      if (btn == "yes") {
                    Ext.Ajax.request({
                        url: "/manager/Extend_CollectSetInfo/UpdateIsPass/" +setId,
                        method: "POST",
                        success: function (d) {
                            //成功后
                            var action = Ext.JSON.decode(d.responseText);
                            //alert(action.success);
                            var flag = action.success;
                            Ext.MessageBox.hide();
                            if (flag == "true") {
                                Extend_CollectSetInfoStore.loadPage(pagingBar.getPageData().currentPage);

                                Ext.helper.msg("恭喜", "更新状态成功!");
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.helper.msg("更新状态失败!", message);
                                }
                                else {
                                    Ext.helper.msg("提示!", "更新状态失败!");
                                }
                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", "修改失败!");
                        }
                    })
                }
                else {

                }
            })
    }

    

    //修改选中行信息
    EditExtend_CollectSetInfoFn = function () {
        var row = Ext.getCmp("Extend_CollectSetInfoPanel").getSelectionModel().getSelection();
        if (row.length == 0) {
            Ext.helper.msg("提示信息", "您没有选中任何行!");
        }
        else if (row.length > 1) {
            Ext.helper.msg("提示信息", "对不起只能选择一个!");
        } else if (row.length == 1) {
            EditExtend_CollectSetInfo(row[0].data.Id, pagingBar.getPageData().currentPage);
        }

    }

    //修改选中行信息
    CopyExtend_CollectSetInfoFn = function () {
        var row = Ext.getCmp("Extend_CollectSetInfoPanel").getSelectionModel().getSelection();
        if (row.length == 0) {
            Ext.helper.msg("提示信息", "您没有选中任何行!");
        }
        else if (row.length > 1) {
            Ext.helper.msg("提示信息", "对不起只能选择一个!");
        } else if (row.length == 1) {
            Ext.Ajax.request({
                url: "/manager/Extend_CollectSetInfo/copy/" + row[0].data.Id,
                method: "get",
                success: function (d) {
                    //成功后
                    var action = Ext.JSON.decode(d.responseText);
                    //alert(action.success);
                    var flag = action.success;
                    if (flag == "true") {
                        Extend_CollectSetInfoStore.loadPage(1);
                        Ext.helper.msg("恭喜", "复制成功!");
                    }
                    else {
                        var message = action.message;
                        if (message) {
                            Ext.MessageBox.alert("复制失败!", message);
                        }
                        else {
                            Ext.MessageBox.alert("提示!", "复制失败!");
                        }
                    }
                },
                failure: function (form, action) {
                    Ext.MessageBox.alert("提示!", "复制失败!");
                }
            })
        }

    }

    //新增信息
    SaveExtend_CollectSetInfoFn = function () {
        InsertExtend_CollectSetInfo();
    }

    //grid配置
    var grid = Ext.create('Ext.grid.Panel', {
        id: "Extend_CollectSetInfoPanel",
        renderTo: "Extend_CollectSetInfoGrid",
        layout: "fit",
        alias: 'widget.methodPanel',
        columnLines: true,
        loadMask: true,
        frame: true,
        border: false,
        selModel: sm,   //选择框
        autoScroll: true,
        store: Extend_CollectSetInfoStore,
        ds: Extend_CollectSetInfoStore,
        sm: sm,
        columnLines: true,
        //cm: cm2,
        viewConfig: {
            stripeRows: true,
            trackOver: true,
            emptyText: '<div style="color:#999;margin:5px;">当前没有记录显示<div>'
        },
        stripeRows: true,
        listeners: {
            "itemdblclick": function (g, rowIndex, e) {
                EditExtend_CollectSetInfoFn();
            }
        },
        bbar: pagingBar,
        tbar: [            		 //工具条设置
            		 {
            		 text: "新增",
            		 tooltip: "新增",
            		 iconCls: "addicon",
            		 handler: SaveExtend_CollectSetInfoFn
           }, "", "-", "", {
               text: "编辑",
               tooltip: "编辑",
               iconCls: "editicon",
               handler: EditExtend_CollectSetInfoFn
           }, "", "-", "", {
               text: "启用",
               tooltip: "编辑",
               iconCls: "editicon",
               handler: UpdateEnabledFn
           }, "", "-", "", {
               text: "启用自动更新",
               tooltip: "编辑",
               iconCls: "editicon",
               handler: UpdateIsAutoUpdateFn
           }, "", "-", "", {
               text: "删除",
               tooltip: "删除",
               iconCls: "deleteicon",
               handler: DeleteExtend_CollectSetInfoFn
           }, "-"],
        columns: [
               Ext.create('Ext.grid.RowNumberer'),
                { header: "序列", dataIndex: "Id", width: 80, sortable: true },
                { header: "采集名称", dataIndex: "Name", width: 220, sortable: true },
                { header: "是否启用", dataIndex: "Enabled", width: 80, renderer: function (value) { if (value == "true") { return "是"; } else { return "否"; } }, sortable: true },
                { header: "是否自动更新", dataIndex: "IsAutoUpdate", width: 80,renderer: function (value) { if (value == "true") { return "是"; } else { return "否"; } }, sortable: true },
                { header: "结束页", dataIndex: "EndNum", width:80, sortable: true },
                { header: "是否分页", dataIndex: "IsPaging", width: 80, sortable: true ,renderer: function (value) { if (value == "true") { return "是"; } else { return "否"; } }},
                { header: "操作", dataIndex: "Id", width: 300, sortable: true, renderer: function (value) { return "<a href='javascript:void(0);' title='全部启用内容' onclick='UpdateIsPass(\"" + value + "\")'  >全部启用内容</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' title='拷贝' onclick='CopyExtend_CollectSetInfoFn()'  >复制</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' title='采集列表维护' onclick='Extend_CollectLinkInfoList(\"" + value + "\")'  >采集列表维护</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' title='采集内容维护' onclick='Extend_CollectContentList(\"" + value + "\")'  >采集内容维护</a>&nbsp;&nbsp;&nbsp;" } },
                { header: "删除", dataIndex: "Id", renderer: function (value) { return "<a href='javascript:void(0);' title='删除' onclick='DeleteExtend_CollectSetInfoFn()'class='deleteBtn' >&nbsp;&nbsp;&nbsp;</a>" }, width: 80 }
            ]
    });
    Extend_CollectSetInfoStore.loadPage(1);
}
    Extend_CollectSetInfoList();
